package top.younote.cherry.selenium;

import lombok.SneakyThrows;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.springframework.stereotype.Service;

import java.net.URL;

/**
 * @Description:
 * @Author: duanluyao
 * @CreateTime: 2022/10/31 11:09
 */
@Service
public class JdService {
    void login() {
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setHeadless(false);
        WebDriver driver = new ChromeDriver(chromeOptions);
        driver.manage().window().setSize(new Dimension(1920, 1080));
        driver.get("https://jd.com");
        WebElement element = driver.findElement(By.xpath("//a[@class=\"link-login\"]"));
        element.click();
        driver.get("https://cart.jd.com/cart_index");
        while (true) {

        }
    }

    @SneakyThrows
    void taobao() {
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setHeadless(false);
//        chromeOptions.setExperimentalOption("debuggerAddress","127.0.0.1:9222");
        WebDriver driver = new ChromeDriver(chromeOptions);
        driver.manage().window().setSize(new Dimension(1920, 1080));
        driver.get("https://www.taobao.com");
        new WebDriverWait(driver, 10000).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class=\"site-nav-sign\"]/a")));
        driver.findElement(By.xpath("//div[@class=\"site-nav-sign\"]/a")).click();
        driver.get("https://cart.taobao.com/cart.htm");
        new WebDriverWait(driver, 10000).until(ExpectedConditions.elementToBeClickable(By.cssSelector("#J_SelectAll1")));
        WebElement j_selectAll1 = driver.findElement(By.cssSelector("#J_SelectAll1"));
        j_selectAll1.click();
        new WebDriverWait(driver, 10000).until(ExpectedConditions.elementToBeClickable(By.cssSelector("#J_SmallSubmit")));
        driver.findElement(By.cssSelector("#J_SmallSubmit")).click();
        new WebDriverWait(driver, 10000).until(ExpectedConditions.elementToBeClickable(By.className("go-btn")));
        driver.findElement(By.className("go-btn")).click();
//        new WebDriverWait(driver,10000).until(ExpectedConditions.elementToBeSelected())
    }
}